AI Verified

Name

Changing “Out of stock” Text with A Snippet

About

Simple products will have the default “out of stock” message. It’s really easy to change this to display another message, such as sold out or anything else. We need to access the woocommerce_get_availability_text filter to change the availability message. We can also change the available stock message. Advanced users can tap into the product details and create unique messages based on any conditions. For example, one condition could be if the product is in a specific category or not. I’ll include some bonus product conditions at the bottom for you to mix and match.

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

add to functions.php

Link for further information:

The author has provided the following URL that may be helpful to setting up or using this snippet:

https://puri.io/blog/change-stock-availability-text-woocommerce/

Codevault

justin's vault

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Snippet Source:

https://puri.io/blog/change-stock-availability-text-woocommerce/

History

Last modified:

21/03/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Changing “Out of stock” Text with A Snippet

 
                    
1/**
2* Change "Out of stock" to "Sold Out"
3* @param string $text
4* @param WC_Product $product
5* @return string
6*/
7function puri_woocommerce_get_availability_text( $text, $product ) {
8 if (!$product->is_in_stock()) {
9 $text = 'Sold out';
10 } else {
11 // You can add more conditions here. e.g if product is available.
12 // $text = 'Available right now';
13 }
14 return $text;
15}
16 
17add_filter( 'woocommerce_get_availability_text', 'puri_woocommerce_get_availability_text', 999, 2);

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

3

WooCommerce Stock Status Progress Bar

Added: 1 year ago

Last Updated: 1 day ago

This snippet inserts a progress bar on the product page to let customers know how many units you have in stock. The visual representation conveys more scarcity because they will be able to see not onl...

WooCommerce

AI Verified

0

Auto Complete all WooCommerce orders

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

WooCommerce Only Allow Number Input For Billing Phone

Added: 1 year ago

Last Updated: 1 year ago

This snippet adds jQuery (run form the footer for performance reasons) which only allows number input in the billing phone field on the checkout. Specifically, it will find and delete anything which i...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

3

Default featured image

Added: 1 year ago

Last Updated: 3 days ago

This code defines a function named default_post_metadata__thumbnail_id that modifies the value of the _thumbnail_id metadata field for a post. The function takes five arguments: $value: The current...

WordPress Admin

AI Verified

2

Completely Disable Comments

Added: 1 year ago

Last Updated: 4 months ago

This will disable comments on the entire site

WordPress Admin

AI Verified

1

Disable Automatic Updates

Added: 1 year ago

Last Updated: 9 months ago

This will disable automatic updates